﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <div>
    <el-form ref="formRefEncodeScheme" :model="stateEncodeScheme.vmModel" label-width="100px">
      <el-row>
        <el-col :xs="24" :lg="24" class="mb20">
        <el-form-item ref="Entity_Name_FormItem" prop="Entity.Name" :label="$t('message.autotrans._Model_EncodeScheme_Name')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_EncodeScheme_Name')}), trigger: 'blur' }]" >
            <el-input v-model="stateEncodeScheme.vmModel.Entity.Name" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="24" class="mb20">
        <el-form-item ref="Entity_Code_FormItem" prop="Entity.Code" :label="$t('message.autotrans._Model_EncodeScheme_Code')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_EncodeScheme_Code')}), trigger: 'blur' }]" >
            <el-input v-model="stateEncodeScheme.vmModel.Entity.Code" clearable></el-input>
        </el-form-item>

        </el-col>

				<el-col :xs="24" :lg="24" class="mb20">
					<el-form-item ref="Entity_FormName_FormItem" prop="Entity.FormName"
												:label="$t('message.autotrans._Model_EncodeScheme_FormName')"
												:rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_EncodeScheme_FormName')}), trigger: 'blur' }]" >
						<el-select v-model="stateEncodeScheme.vmModel.Entity.FormName"  @change="onFormChange" clearable>
							<el-option v-for="item in stateEncodeScheme.AllForms" :key="item.Text" :value="item.Value" :label="item.Text"></el-option>
						</el-select>
					</el-form-item>

				</el-col>


<!--        <el-col :xs="24" :lg="24" class="mb20">-->
<!--        <el-form-item ref="Entity_FormCode_FormItem" prop="Entity.FormCode" :label="$t('message.autotrans._Model_EncodeScheme_FormCode')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_EncodeScheme_FormCode')}), trigger: 'blur' }]" >-->
<!--            <el-input v-model="stateEncodeScheme.vmModel.Entity.FormCode" clearable></el-input>-->
<!--        </el-form-item>-->

<!--        </el-col>-->
<!--        <el-col :xs="24" :lg="24" class="mb20">-->
<!--        <el-form-item ref="Entity_SerialNumber_FormItem" prop="Entity.SerialNumber" :label="$t('message.autotrans._Model_EncodeScheme_SerialNumber')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_EncodeScheme_SerialNumber')}), trigger: 'blur' }]" >-->
<!--            <el-input v-model="stateEncodeScheme.vmModel.Entity.SerialNumber" clearable></el-input>-->
<!--        </el-form-item>-->

<!--        </el-col>-->
        <el-col :xs="24" :lg="24" class="mb20">
        <el-form-item ref="Entity_Remark_FormItem" prop="Entity.Remark" :label="$t('message.autotrans._Model_EncodeScheme_Remark')">
            <el-input v-model="stateEncodeScheme.vmModel.Entity.Remark" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="24" class="mb20">
        <el-form-item ref="Entity_Active_FormItem" prop="Entity.Active" :label="$t('message.autotrans._Model_EncodeScheme_Active')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_EncodeScheme_Active')}), trigger: 'blur' }]" >
            <el-switch v-model="stateEncodeScheme.vmModel.Entity.Active" clearable></el-switch>
        </el-form-item>

        </el-col>
      </el-row>

      <WtmTable ref="tableRefEncodeItemSchemeList" v-bind="tableDataEncodeItemSchemeList" v-model="stateEncodeScheme.vmModel.Entity.EncodeItem_Scheme"></WtmTable>
      <div style="text-align:right;">
        <WtmButton @click="onSubmitEncodeScheme"  type="primary" :button-text="$t('message.autotrans.SysSubmit')" style="margin-top:15px;"/>

        <WtmButton @click="onCloseEncodeScheme"  type="primary" :button-text="$t('message.autotrans.SysClose')" style="margin-top:15px;"/>

      </div>

    </el-form>

  </div>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageFactoryManagementEncodeSchemeCreate;false">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { encodeschemeApi } from '/@/api/factorymanagement/encodescheme';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;


// 定义变量内容
const tableRefEncodeItemSchemeList = ref();
const tableDataEncodeItemSchemeList = ref({
    // 列表数据（必传）
    data: [],
	// 表头内容（必传，注意格式）
	header: [
      {title:ci.proxy.$t('message.autotrans.Page值名称'),key: 'ValueName',type: 'textbox',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page值类型'),key: 'ValueMode',type: 'combobox',comboData:{
                Custom:ci.proxy.$t('message.autotrans._Enum_ValueTypeEnum_Custom'),
                SerialNumber:ci.proxy.$t('message.autotrans._Enum_ValueTypeEnum_SerialNumber'),
                Parameter:ci.proxy.$t('message.autotrans._Enum_ValueTypeEnum_Parameter'),
                FixedValue:ci.proxy.$t('message.autotrans._Enum_ValueTypeEnum_FixedValue'),},isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page值'),key: 'Value',type: 'textbox',isCheck: true},
      {title:ci.proxy.$t('message.autotrans._AdminDisplayOrder'),key: 'Pos',type: 'textbox',sortable:'custom',isCheck: true},
      {title:ci.proxy.$t('message.autotrans._AdminRemark'),key: 'Remark',type: 'textbox',isCheck: true},

	],
	// 配置项（必传）
	config: {
        total: 0, // 列表总数
		loading: false, // loading 加载
		isSerialNo: true, // 是否显示表格序号
		isSelection: true, // 是否显示表格多选
		isOperate: true, // 是否显示表格操作栏
        isSub:true,
        isDisabled:false
	}
});

// 定义变量内容
const formRefEncodeScheme = ref();
const stateEncodeScheme = reactive({
    vmModel: {
	  Entity:{
        Name: '',
        Code: '',
        FormName: '',
        FormCode: '',
        SerialNumber: 1,
        Remark: '',
        Active: true,
        EncodeItem_Scheme:[],
      },

	},
    AllForms:[] as any[],
    AllSchemes: [] as any[],
});

// 取消
const onCloseEncodeScheme = () => {
    closeDialog();
};


//当选择表单
const onFormChange = (value: any) =>
{

	if (value)
	{
	 	stateEncodeScheme.vmModel.Entity.FormCode = stateEncodeScheme.AllForms.find((x)=>x.Value === value).Text;
	}
	else{
		stateEncodeScheme.vmModel.Entity.FormCode = value;
	}

}


// 提交
const onSubmitEncodeScheme = () => {
 	const loadingInstance = ElLoading.service({
		lock: true,
		text: '正在提交中，请等待。。。',
		background: 'rgba(0, 0, 0, 0.7)',
	});
   formRefEncodeScheme.value?.validate((valid: boolean, fields: any) => {
		if (valid) {
            encodeschemeApi().add(stateEncodeScheme.vmModel).then(() => {
                ElMessage.success(ci.proxy.$t('message._system.common.vm.submittip'));
                emit('refresh');
                closeDialog();
            }).catch((error) => {
                other.setFormError(ci, error);
            }).finally(() => {
			loadingInstance.close();
		    })
		}
        else{
			loadingInstance.close();
        }
	})
};

// 页面加载时
onMounted(() => {
    other.getSelectList('/api/FactoryManagement/EncodeScheme/GetForms',[],false).then(x=>{stateEncodeScheme.AllForms = x});
    other.getSelectList('/api/FactoryManagement/EncodeItem/GetEncodeSchemes',[],false).then(x=>{stateEncodeScheme.AllSchemes = x});
});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh','closeDialog']);
// 关闭弹窗
const closeDialog = () => {
    emit('closeDialog');
};
// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

